﻿using System.Collections.ObjectModel;
using System.Windows.Input;
using IS_Ever_Green.DataAccess.Model;
using IS_Ever_Green.DataAccess.Model.Repositories;

namespace IS_Ever_Green.ViewModel
{
    public class HomeUserViewModel : BaseViewModel
    {
        private IProductRepository _productRepository;
        private ObservableCollection<ProductModel> _readyComputerList;
        private ObservableCollection<ProductModel> _accessoriesList;
        private ObservableCollection<ProductModel> _laptopList;
        private ObservableCollection<ProductModel> _phoneList;
        private string _textReadyComputer;
        private string _textAccessories;
        private string _textLaptop;
        private string _textPhone;

        public ObservableCollection<ProductModel> ReadyComputerList
        {
            get { return _readyComputerList; }
            set { _readyComputerList = value; OnPropertyChanged(nameof(ReadyComputerList)); }
        }

        public ObservableCollection<ProductModel> AccessoriesList
        {
            get { return _accessoriesList; }
            set { _accessoriesList = value; OnPropertyChanged(nameof(AccessoriesList)); }
        }

        public ObservableCollection<ProductModel> LaptopList
        {
            get { return _laptopList; }
            set { _laptopList = value; OnPropertyChanged(nameof(LaptopList)); }
        }

        public ObservableCollection<ProductModel> PhoneList
        {
            get { return _phoneList; }
            set { _phoneList = value; OnPropertyChanged(nameof(PhoneList)); }
        }

        public string TextReadyComputer
        {
            get { return _textReadyComputer; }
            set { _textReadyComputer = value; OnPropertyChanged(nameof(TextReadyComputer)); }
        }

        public string TextAccessories
        {
            get { return _textAccessories; }
            set { _textAccessories = value; OnPropertyChanged(nameof(TextAccessories)); }
        }

        public string TextLaptop
        {
            get { return _textLaptop; }
            set { _textLaptop = value; OnPropertyChanged(nameof(TextLaptop)); }
        }

        public string TextPhone
        {
            get { return _textPhone; }
            set { _textPhone = value; OnPropertyChanged(nameof(TextPhone)); }
        }


        public ICommand AddProductCart { get; }
        public ICommand AddProductLike { get; }
        public ICommand DeleteProductCart { get; }
        public ICommand DeleteProductLike { get; }

        public HomeUserViewModel()
        {
            _productRepository = new ProductRepository();

            ShowProductFromReadyComputer();
            ShowProductFromAccessories();
            ShowProductFromLaptop();
            ShowProductFromPhone();
        }

        public void ShowProductFromReadyComputer()
        {
            ReadyComputerList = new ObservableCollection<ProductModel>(_productRepository.GetProductWithCategory(1));
            if(ReadyComputerList.Count != 0)
            {
                TextReadyComputer = "Готовые ПК";
            }
        }

        public void ShowProductFromAccessories()
        {
            AccessoriesList = new ObservableCollection<ProductModel>(_productRepository.GetProductWithCategory(2));
            if (AccessoriesList.Count != 0)
            {
                TextAccessories = "Комплектующие";
            }
        }

        public void ShowProductFromLaptop()
        {
            LaptopList = new ObservableCollection<ProductModel>(_productRepository.GetProductWithCategory(3));
            if (LaptopList.Count != 0)
            {
                TextLaptop = "Ноутбуки";
            }
        }

        public void ShowProductFromPhone()
        {
            PhoneList = new ObservableCollection<ProductModel>(_productRepository.GetProductWithCategory(4));
            if (PhoneList.Count != 0)
            {
                TextPhone = "Телефоны";
            }
        }
    }
}
